<%@ page import="cn.hutool.db.Db" %>
<%@ page import="com.dengcj.epl.dao.DB" %>
<%@ page import="cn.hutool.db.Entity" %>
<%@ page import="cn.hutool.http.HttpRequest" %>
<%@ page import="cn.hutool.json.JSONUtil" %><%--
  Created by IntelliJ IDEA.
  User: dengchunjie
  Date: 2022/1/12
  Time: 15:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  boolean dbValidate = false;
  try {
    DB db = new DB();
    Entity entity = db.queryOne("select 1");
    if(entity != null) {
      dbValidate = true;
    }
  } catch (Exception e){
    e.printStackTrace();
  }

  boolean jerseyValidate = false;
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+"/";

  String result = HttpRequest.get(basePath+"api/internal/check").execute().body();
  if(JSONUtil.isJson(result)){
    jerseyValidate = true;
  }

%>
<html>
  <head>
    <title>EcologyPluginLite</title>
    <style type="text/css">
      .statusimg{
        width: 20px;
      }

      table,td,th{
        border: 1px solid lightgray;
        border-collapse: collapse;
      }

      td{
        padding: 5px;
      }
    </style>
  </head>
  <body>
  <table>
    <thead>
      <tr>
        <th>检查项</th>
        <th>状态</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Database</td>
        <td><img class="statusimg" src="img/<%=dbValidate %>.png"></td>
      </tr>
      <tr>
        <td>Jersey</td>
        <td><img class="statusimg" src="img/<%=jerseyValidate %>.png"></td>
      </tr>
    </tbody>
  </table>
  </body>
</html>
